﻿using System.ComponentModel.DataAnnotations;
using TravelServer.DTOs;

namespace TravelServer.ValidationAttributes
{
    /// <summary>
    /// 类级别数据验证特性
    /// 验证规则在IsValid方法里实现
    /// 只需要给需要验证的类打上该标签即可
    /// </summary>
    public class TouristRouteCreationDtoValidationAttribute:ValidationAttribute
    {
        protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
        {
            var touristRouteCreatDto=validationContext.ObjectInstance as TouristRouteCreationDto;
            if (touristRouteCreatDto?.Title == touristRouteCreatDto?.Description)
            {
                return new ValidationResult("标题不能与描述内容一样！", new[] { "TouristRouteCreationDto" });
            }
            return ValidationResult.Success;
        }
    }
}
